/******************************************************************************/
/*  Class MODEM                                                               */
/*  SW: S. Maslyakov, rusoil.9@gmail.com                                      */
/*                                                                            */
/*  Revision:     1.1                                                         */
/*  Date:         2010/12/23 20:00:33                                         */
/******************************************************************************/


#ifndef __MODEM_H
#define __MODEM_H


#include "Uart\uart1.h"
#include "Pdu\pdu.h"
#include "modem_def.h"


//==============================================================================
//  Class MODEM
//==============================================================================
class MODEM : public UART1, public PDU
{
public:
  static void Init_Modem();
  static void InterruptHandlerUart1();
  static void Init_modem_task();
  static void Activate_modem_task();
  static void * Get_modem_mutex();
  static void * Get_modem_event();
  static void * Get_dataok_event();
  static void * Get_modem_cmd_dque();
  static void ProcessTimeout();
  inline static bool_t IsModemOn() { return (FIO1PIN_bit.P1_26) ? TRUE_T : FALSE_T; }
  inline static bool_t IsPinOk() { return m_mdFlg.isPinOk; }
  inline static bool_t IsGprsConn() { return m_tcpTools.isGprsConn; }
  inline static bool_t IsTcpConn() { return m_tcpTools.isTcpConn; }
  inline static bool_t IsTransparent() { return m_tcpTools.isTransparentMode; }

private:
  static void Init_rtos_part();
  static void Task_modem_poll(void * par);
  static void Task_modem_pars(void * par);
  static void Task_modem_incom_data(void * par);
  static void SetStatus(const uint16_t _stats);
  static void ModemOn();
  static void ModemOff();
  static void ModemVendorInfo();
  static bool_t TestModemState();
  static bool_t ValidateIncomingNumber(const int8_t * const _pNum);
  static void ModemStatusHandler(const uint8_t _status);
  static void SendData(const __MD_DATA * const _pData);
  static void AT_CGMI();
  static void AT_CGMM();
  static void AT_CGMR();
  static void AT_CGSN();
  static void AT_COPS();
  static void AT_CSQ();
  static void AT_CSCA();
  static void AT_CMGR();
  static void RunCommand(const __MD_CMD_DATA * const cmd);
  static void ParserAtCommand(const uint8_t _byte);
  static void ParsingIncomData(const uint8_t * const _pBuff,
                               const uint16_t _dataLen);
  static void DebugConfigure();
  static sint32_t ReleaseMem(const __MD_ANSW_DATA * const _pMem);
  static sint32_t SendCmd(const __MD_CMD * const _pCmd);
  static bool_t SmsConfigure();
  static bool_t TcpConfigure();
  static bool_t GprsConnect();
  static bool_t TcpConnect(const __MD_SRV * const _srv);
  static bool_t TcpClose();
  static bool_t TcpTransparentMode();
  static bool_t TcpCmdMode();
  static bool_t SrvConnect();
  static bool_t SrvDisconnect();
  static bool_t AT_CMGD(const uint16_t _cell);
  static bool_t AT_CMGS(const __MD_SMS * const _pSms);
  static bool_t ParsingUnsolMsg(const uint8_t * const _pBuff,
                                const uint16_t _dataLen);
  inline static void SetPowerKey() { FIO1CLR_bit.P1_28 = 1; }
  inline static void ClearPowerKey() { FIO1SET_bit.P1_28 = 1; }

  static __MD_TCP_TOOLS m_tcpTools;
  static __MD_STATUS_FLG m_mdFlg;
  static __MD_INFO m_mdInfo;
  static __MD_SIM_INFO m_simInfo;
  static __MD_PARSING_TOOLS m_mdPars;
};
//==============================================================================
//==============================================================================


#endif